from rest_framework.permissions import BasePermission
from utils.exceptions import Unauthorized, PermissionDenied


class IsLogin(BasePermission):
    def has_permission(self, request, view):
        if request.user and request.user.is_anonymous:
            raise Unauthorized()
        return True


class IsAdmin(BasePermission):
    def has_permission(self, request, view):
        if request.user and not request.user.is_anonymous and request.user.is_admin:
            return True
        raise PermissionDenied()
